package it.univpm.diiga.memorysim.kernel.shared;

import java.util.Comparator;


public class ProcessRequest implements MemoryElement,Comparator<ProcessRequest>{
	private int PID = 0;
	private int dimProcess = 0;
	private int segmento = -1;
	private int pagina = -1;
	private int offset = 0;
	private int dimBlock=0; //dimensione segmento o pagina
	private int durata = 0;
	private boolean lastRequest = false;
	private String type="";
	//private int nBlock=0;
	
	private int start;
	private int end;
	
	//segmentazione
	public ProcessRequest(int PID,int segmento,int offset,int dimSegmento, int dimProcess, int durata){
		this.PID=PID;
		this.segmento=segmento;
		this.offset=offset;
		this.dimBlock=dimSegmento;
		this.dimProcess=dimProcess;
		this.durata=durata;
	}
	
	//segmentazione con paginazione
	public ProcessRequest(int PID,int segmento,int pagina,int offset,int dimSegmento, int dimProcess,int durata){
		this.PID=PID;
		this.segmento=segmento;
		this.pagina=pagina;
		this.offset=offset;
		this.dimBlock= dimSegmento;
		this.dimProcess=dimProcess;
	}
	
	//paginazione
	public ProcessRequest(int PID,int pagina,int offset, int dimProcess, int durata, boolean lastRequest){
		this.PID=PID;
		this.pagina=pagina;
	    this.offset=offset;
		this.dimProcess=dimProcess;
		this.lastRequest=lastRequest;
	}
	
	//creato dal team dell'interfaccia!!!
	public ProcessRequest(int PID,int pagina,String type){
		this.PID=PID;
		this.pagina=pagina;
		this.type=type;
	}
	
	//creato dal team dell'interfaccia!!!
	public ProcessRequest(int PID,int seg,String type,int block){
		this.PID=PID;
		this.segmento=seg;
		this.type=type;
		this.dimBlock=block;
	}
	
	public void setDurata(int durata){
		this.durata=durata;
	}
	
	public void setPID(int PID){
		this.PID=PID;
	}
	
	public void setDimProcess(int dim){
		this.dimProcess=dim;
	}
	
	public void setDimBlock(int dim){
		this.dimBlock=dim;
	}
	
	public void setPagina(int pagina){
		this.pagina=pagina;
	}
	
	public void setSegmento(int segmento){
		this.segmento=segmento;
	}
	
	public void setOffset(int offset){
		 this.offset=offset;
	}
	
	public void setLastRequest(boolean lastRequest){
		 this.lastRequest=lastRequest;
	}

	
	public boolean getLastRequest(){
		return this.lastRequest;
	}
	
	public int getDurata(){
		return this.durata;
	}
	
	public int getPID(){
		return this.PID;
	}
	
	public String getType(){
		return this.type;
	}
	
	public int getDimProcess(){
		return this.dimProcess;
	}
	
	
	public int getDimBlock(){
		
		if (this.dimBlock==0)
			this.dimBlock=Parameters.getDimPage();
		return this.dimBlock;
	}
	
	public int getTableRow(){
		if(this.pagina != -1)
			return this.pagina;
		else
			return this.segmento;
	}
	
	
	public int getPagina(){
		return this.pagina;
	}
	
	public int getSegmento(){
		return this.segmento;
	}
	
	public int getOffset(){
		 return this.offset;
	}
	

	
	
	
	
	/*
	 * INDIRIZZI FISICI
	 */
	public void setStart(int start){
		this.start=start;
	}
	
	public void setEnd(int end){
		this.end=end;
	}
	
	public int getStart(){
		return start;
	}
	
	public int getEnd(){
		return end;
	}
	
	
	public int compare(ProcessRequest proc1, ProcessRequest proc2) {
		//ProcessRequest proc1 = (ProcessRequest)p1;
		//ProcessRequest proc2 = (ProcessRequest)p2;
		if(proc1.getStart() < proc2.getStart()) return -1;
		if(proc1.getStart() > proc2.getStart()) return 1;
		return 0;
	}
	
	public String toString(){
		return  "Process: "+this.PID+"\n"+
				"Pagina: "+this.pagina+"\n"+
				"Segmento: "+this.segmento+"\n"+
				"Offset: "+this.offset+"\n"+
				"Start: "+this.start+"\n"+
				"End: "+this.end;
	}

	
		                      
}
